//
//  AddTagViewController.m
//  HAODE
//
//  Created by LiYinDi on 16/1/29.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "AddTagViewController.h"
#import "Masonry.h"
#import "HttpRequest.h"
@interface AddTagViewController ()

@end

@implementation AddTagViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation];
    [self setAutoLayout];
}
-(void)setAutoLayout
{
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.equalTo(self.view.mas_left);
       make.right.equalTo(self.view.mas_right);
         make.height.equalTo(@50);
        make.top.equalTo(self.view.mas_top).with.offset(64);
    }];
}
-(void)setNavigation
{
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem* leftBtnItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBtnItem;
    
    UILabel* titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0,40, 23)];
    titleLabel.text=@"添加标签";
    titleLabel.font=[UIFont systemFontOfSize: 19];
    self.navigationItem.titleView=titleLabel;
    
  UIButton *  rightBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 1, 1, 1)];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    
    [rightBtn setTitleColor:[UIColor colorWithRed:6.0f/255.0f green:113.0f/255.0f blue:118.0f/255.0f alpha:1.0]forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    rightBtn.width=40;
    rightBtn.height=64;
    [rightBtn addTarget:self action:@selector(saveBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightBtnItem;
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone:) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone:) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone:) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    _tagTextField.inputAccessoryView = myToolBar;
}
-(void)OnTapDone:(UITextField *)textfield{
    [_tagTextField resignFirstResponder];
}
-(void)saveBtnClick
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:_optionNameStr forKey:@"optionName"];
    [param setValue:_tagTextField.text forKey:@"content"];
//     NSLog(@"====－－－－－－－%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/AppCode/Add" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
           //  NSLog(@"====－－－－－－－%@",severDataDict.dataDict);
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                [self.navigationController popViewControllerAnimated:YES];
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

}
-(void)BackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
